//
//  AWChatMessage.h
//  AtWork2
//
//  Created by lucas on 15/4/16.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWMessage.h"
#import "AWMessageSendStatus.h"
#import <UIKit/UIKit.h>

@class ATWFileInfo;

/**
 *  聊天消息类型。
 */
typedef NS_ENUM(NSUInteger, AWChatMessageType) {
    
    /** 文本 */
    AWChatMessageTypeText    = 0,
    
    /** 图片 */
    AWChatMessageTypeImage   = 1,
    
    /** 语音 */
    AWChatMessageTypeVoice   = 2,
    
    /** 文件 */
    AWChatMessageTypeFile    = 3,
    
    /** 系统 */
    AWChatMessageTypeSystem  = 4,
    
    /** 图文 */
    AWChatMessageTypeArticle = 5,
    
    /** 事件 */
    AWChatMessageTypeEvent   = 6
};

/**
 * 聊天类型
 */
typedef NS_ENUM(NSUInteger, AWChatDestType) {
    
    /** 点对对 单聊 */
    AWChatDestTypeP2P           = 0,
    
    /** 讨论组 */
    AWChatDestTypeDiscussion
};

/**
 * 聊天消息发送者类型
 */
typedef NS_ENUM(NSUInteger, AWChatMessageSenderType) {
    AWChatMessageSenderFrom     = 0,
    AWChatMessageSenderTo
};

static inline NSString * base64WithData(NSData *data) {
    return [[data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength] stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
}

static inline NSData * base64WithString(NSString *content) {
    return [[NSData alloc] initWithBase64EncodedString:content options:NSDataBase64DecodingIgnoreUnknownCharacters];
}

static inline AWChatMessageType parseChatMessageType(NSString *chatMessageType) {
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKText]) {
        return AWChatMessageTypeText;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKImage]) {
        return AWChatMessageTypeImage;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKVoice]) {
        return AWChatMessageTypeVoice;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKFile]) {
        return AWChatMessageTypeFile;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKSystem]) {
        return AWChatMessageTypeSystem;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKArticle]) {
        return AWChatMessageTypeArticle;
    }
    if ([chatMessageType.uppercaseString isEqualToString:AWMessageKEvent]) {
        return AWChatMessageTypeEvent;
    }
    return  NSNotFound;
}

/**
 *  聊天消息。
 */
@interface AWChatMessage : AWMessage


@property (nonatomic,assign) CGSize cellSize;

@property (nonatomic, assign) AWChatMessageType chatMessageType;

@property (nonatomic, assign) AWChatDestType chatDestType;

@property (nonatomic, assign) AWChatMessageSenderType chatMessageSenderType;

/** 可搜索内容 (根据不同聊天消息类型) */
@property (nonatomic, copy, readonly) NSString *searchableContent;

@property (nonatomic, assign) AWMessageSendStatus chatMessageSendStatus;

@property (nonatomic, assign, getter=hasRead) BOOL read;

@property (nonatomic, assign, getter = isGroup) BOOL group;

/** 显示的名称 */
@property (nonatomic, copy, readwrite) NSString *displayName;

/** 显示的头像 */
@property (nonatomic, copy, readwrite) NSString *displayAvatar;

@property (nonatomic, copy, readonly) NSString *targetUrl;

@property (nonatomic, strong) ATWFileInfo *fileInfo;

@end
